package com.ruoyi.service.impl;


import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.domain.CustomerBasicRate;
import com.ruoyi.domain.CustomerCost;
import com.ruoyi.dto.EconomyDTO;
import com.ruoyi.mapper.CustomerBillMapper;
import com.ruoyi.service.CustomerBillService;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class CustomerBillServiceImpl implements CustomerBillService {

    @Autowired
    private CustomerBillMapper customerBillMapper;

    /**
     * 01-19版本模板导出
     */
    @Override
    public void exportCustomerCostTemplate(HttpServletResponse response) throws Exception {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 使用 EasyExcel 创建 Excel 写入器
        try {
            // 初始化写入器
            var excelWriter = EasyExcel.write(outputStream).head(CustomerCost.class).build();
            // 创建一个 WriteSheet 对象，用于指定工作表的名称
            WriteSheet writeSheet = EasyExcel.writerSheet("一件代发").head(getCustomerCost()).build();
            // 将所有数据写入这个工作表
            excelWriter.write((Collection<?>) null, writeSheet);
            // 关闭写入器
            excelWriter.finish();
            // 设置响应头，指示浏览器下载
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Content-Disposition", "attachment; filename=fileName.xlsx");
            // 写入输出流
            response.getOutputStream().write(outputStream.toByteArray());
            response.getOutputStream().flush();
        } finally {
            outputStream.close();
        }
        System.out.println("6666666666666666666666666666666666666666666666666666666");
    }


    /**
     * 01-19版本
     */
    @Override
    public void customerCost(HttpServletResponse response, MultipartFile costFile, MultipartFile detailsFile, boolean updateSupport) throws Exception {
        System.out.println("----------------------------------客户的成本开始-----------------------------");
        //导入库内操作表
        ExcelUtil<CustomerCost> costUtil = new ExcelUtil<CustomerCost>(CustomerCost.class);
        List<CustomerCost> costList = new ArrayList<>();
        String type = null;
        // 导入第一个Excel文件
        if (costFile.getOriginalFilename() != null) {
            costList = costUtil.importExcel(costFile.getInputStream());
            if (costFile.getOriginalFilename().contains("一件代发")) {
                type = "AM";
            }
        }
        //AE客户基础费用
        List<CustomerBasicRate> AECustomer = customerBillMapper.getAECustomer();
        //ECO客户基础费用
        List<CustomerBasicRate> ECOCustomer = customerBillMapper.getECOCustomer();
        //AM-AEO客户基础费用
        List<CustomerBasicRate> AMAEOCustomer = customerBillMapper.getAMAEOCustomer();
        //ECONOMY 偏远 超偏远邮编
        List<EconomyDTO> economyCodeList = customerBillMapper.getEconomyCode();
        //实重(LB)
        BigDecimal conversionFactor = new BigDecimal("0.0022046");
        //英尺换算--0.393700787402
        BigDecimal acre = new BigDecimal("0.393700787402");
        costList.remove(0);
        for (CustomerCost lo : costList) {
            // 构造错误信息
            List<List<String>> data = new ArrayList<>();
            if (lo.getPostalCode().length() < 5) {
                data.add(Collections.singletonList("邮编长度错误,邮编为:" + lo.getPostalCode()));
            } else if (lo.getLength() == null || lo.getHeight() == null || lo.getWidth() == null || lo.getWeight() == null) {
                data.add(Collections.singletonList("长宽高计费重错误,运单号为为::" + lo.getWaybillNum()));
            } else if (lo.getLogisticsProvider() == null || lo.getLogisticsMethod() == null) {
                data.add(Collections.singletonList("物流商或物流方式错误,运单号为为::" + lo.getWaybillNum()));
            } else if (lo.getPartition() == null || lo.getPartition().isEmpty()) {
                data.add(Collections.singletonList("分区错误,运单号为为::" + lo.getWaybillNum()));
            }
            // 如果有错误信息，则立即导出并返回
            if (!data.isEmpty()) {
                // 设置响应头
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                response.setHeader("Content-Disposition", "attachment; filename=error_info.xlsx");

                try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
                    // 设置表头
                    List<List<String>> head = new ArrayList<>();
                    head.add(Collections.singletonList("错误"));

                    // 使用 EasyExcel 写入错误数据
                    EasyExcel.write(outputStream)
                            .head(head)
                            .sheet("错误信息")
                            .doWrite(data);

                    response.getOutputStream().write(outputStream.toByteArray());
                    response.getOutputStream().flush();
                }
                return; // 提前结束方法，只导出当前错误信息，其他不处理
            }
        }
        costList.parallelStream().forEach(item -> {
            if ("FedEx".equalsIgnoreCase(item.getLogisticsProvider()) && !("wareHouse").equals(item.getWareHouse())) {
                customerCost(item);
                if (!"是".equals(item.getWaybill()) && !"-".equals(item.getLogisticsMethod()) && item.getLogisticsMethod() != null) {
                    Integer partition = Integer.valueOf(item.getPartition());
                    //AE
                    if ("AE".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                        //基础运费成本
                        for (CustomerBasicRate rate : AECustomer) {
                            if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                                    && rate.getZones().equals(item.getPartition())
                            ) {
                                item.setBaseRateCost(rate.getPrice());
                                item.setAmount(item.getAmount().add(rate.getPrice()));
                                break;
                            }
                        }
                        //住宅附加费
                        if (item.getResidentialSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                            item.setResidentialSurchargeCost(new BigDecimal(2.40).setScale(2, RoundingMode.HALF_UP));
                            item.setAmount(item.getAmount().add(item.getResidentialSurchargeCost()));
                        }
                        //偏远地区
                        for (EconomyDTO dto : economyCodeList) {
                            if (dto.getCode().equals(item.getPostalCode().trim().substring(0, 5))) {
                                if ("偏远".equals(dto.getType())) {
                                    if (item.getDeliveryAreaSurcharge() != null) {
                                        if (item.getDeliveryAreaSurcharge().compareTo(new BigDecimal(2.51)) >= 0) {
                                            item.setDeliveryAreaSurchargeCost(new BigDecimal(3.70));
                                        } else {
                                            item.setDeliveryAreaSurchargeCost(new BigDecimal(2.51));
                                        }
                                    } else {
                                        item.setDeliveryAreaSurchargeCost(new BigDecimal(3.70).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    item.setAmount(item.getAmount().add(item.getDeliveryAreaSurchargeCost()));
                                    break;
                                } else if ("超偏远".equals(dto.getType())) {
                                    if (item.getDASEXTENDEDHomeDelivery() != null) {
                                        if (item.getDeliveryAreaSurcharge().compareTo(new BigDecimal(3.14)) >= 0) {
                                            item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal(4.95));
                                        } else {
                                            item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal(3.14));
                                        }
                                    } else {
                                        item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal(4.95));
                                    }
                                    item.setAmount(item.getAmount().add(item.getDeliveryAreaSurchargeExtendedCost()));
                                    break;
                                } else if ("超级偏远".equals(dto.getType())) {
                                    item.setDeliveryAreaSurchargeRemoteResidentialCost(new BigDecimal(8.86).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDeliveryAreaSurchargeRemoteResidentialCost()));
                                    break;
                                }
                            }
                        }
                        //燃油附加费利率
                        BigDecimal interestRate = item.getFuelSurcharge().divide(
                                item.getTotalCost().subtract(item.getFuelSurcharge()),
                                2,
                                RoundingMode.HALF_UP
                        );
                        if (interestRate.compareTo(BigDecimal.ZERO) != 0) {
                            item.setFuelSurchargeCost(item.getAmount().multiply(interestRate).setScale(2, RoundingMode.HALF_UP));
                            item.setAmount(item.getAmount().add(item.getFuelSurchargeCost()));
                        }
                    }
                    //ECO
                    if (item.getLogisticsMethod().contains("ECONOMY")) {
                        //基础运费成本
                        for (CustomerBasicRate rate : ECOCustomer) {
                            if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                                    && rate.getZones().equals(item.getPartition())) {
                                item.setBaseRateCost(rate.getPrice());
                                item.setAmount(item.getAmount().add(item.getBaseRateCost()));
                                break;
                            }
                        }
                        //偏远地区
                        for (EconomyDTO dto : economyCodeList) {
                            if (dto.getCode().equals(item.getPostalCode().trim().substring(0, 5))) {
                                if ("偏远".equals(dto.getType())) {
                                    item.setDeliveryAreaSurchargeCost(new BigDecimal(2.98).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDeliveryAreaSurchargeCost()));
                                    break;
                                } else if ("超偏远".equals(dto.getType())) {
                                    item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal(3.98).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDeliveryAreaSurchargeExtendedCost()));
                                    break;
                                } else if ("超级偏远".equals(dto.getType())) {
                                    item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal(3.98).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDeliveryAreaSurchargeExtendedCost()));
                                    break;
                                }
                            }
                        }
                        //燃油附加费利率
                        BigDecimal interestRate = item.getFuelSurcharge().divide(
                                item.getTotalCost().subtract(item.getFuelSurcharge()), 2, RoundingMode.HALF_UP);
                        if (interestRate.compareTo(BigDecimal.ZERO) != 0) {
                            item.setFuelSurchargeCost(item.getAmount().multiply(interestRate).setScale(2, RoundingMode.HALF_UP));
                            item.setAmount(item.getAmount().add(item.getFuelSurchargeCost()));
                        }

                    }
                    //AM-AEO-_C
                    if ("AM".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                            "_C".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                            "EO".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                        //基础运费成本
                        for (CustomerBasicRate rate : AMAEOCustomer) {
                            if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                                    && rate.getZones().equals(item.getPartition())
                            ) {
                                item.setBaseRateCost(rate.getPrice());
                                item.setAmount(item.getAmount().add(rate.getPrice()));
                                break;
                            }
                        }
                        //--------------------------------
                        //偏远地区附加费1
                        if (item.getDASResi() != null) {
                            if (item.getDASResi().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASResiCost(new BigDecimal("3.70"));
                                item.setAmount(item.getDASResiCost().add(item.getAmount()));
                            }
                        }
                        //偏远地区附加费2
                        if (item.getDASGround() != null) {
                            if (item.getDASGround().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASGroundCost(new BigDecimal("2.51"));
                                item.setAmount(item.getDASGroundCost().add(item.getAmount()));
                            }
                        }
                        //偏远地区附加费3
                        if (item.getDeliveryAreaSurcharge() != null) {
                            if (item.getDeliveryAreaSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDeliveryAreaSurchargeCost(new BigDecimal("3.70"));
                                item.setAmount(item.getDeliveryAreaSurchargeCost().add(item.getAmount()));
                            }
                        }
                        //超偏远地区附加费1
                        if (item.getDASEXTENDEDHomeDelivery() != null) {
                            if (item.getDASEXTENDEDHomeDelivery().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASEXTENDEDHomeDeliveryCost(new BigDecimal("4.95"));
                                item.setAmount(item.getDASEXTENDEDHomeDeliveryCost().add(item.getAmount()));
                            }
                        }
                        //超偏远地区附加费2
                        if (item.getDASEXTENDEDGround() != null) {
                            if (item.getDASEXTENDEDGround().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASEXTENDEDGroundCost(new BigDecimal("3.14"));
                                item.setAmount(item.getDASEXTENDEDGroundCost().add(item.getAmount()));
                            }
                        }
                        //超偏远地区附加费3
                        if (item.getDeliveryAreaSurchargeExtended() != null) {
                            if (item.getDeliveryAreaSurchargeExtended().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal("4.95"));
                                item.setAmount(item.getDeliveryAreaSurchargeExtendedCost().add(item.getAmount()));
                            }
                        }
                        //超级偏远地区附加费1
                        if (item.getDASRemoteComm() != null) {
                            if (item.getDASRemoteComm().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASRemoteCommCost(new BigDecimal("8.86"));
                                item.setAmount(item.getDASRemoteCommCost().add(item.getAmount()));
                            }
                        }
                        //超级偏远地区附加费2
                        if (item.getDASRemoteResi() != null) {
                            if (item.getDASRemoteResi().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASRemoteResiCost(new BigDecimal("8.86"));
                                item.setAmount(item.getDASRemoteResiCost().add(item.getAmount()));
                            }
                        }
                        //超级偏远地区附加费3
                        if (item.getDeliveryAreaSurchargeRemoteResidential() != null) {
                            if (item.getDeliveryAreaSurchargeRemoteResidential().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDeliveryAreaSurchargeRemoteResidentialCost(new BigDecimal("8.86"));
                                item.setAmount(item.getDeliveryAreaSurchargeRemoteResidentialCost().add(item.getAmount()));
                            }
                        }
                        if (item.getResidentialSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                            item.setResidentialSurchargeCost(new BigDecimal(2.90));
                            item.setAmount(item.getAmount().add(item.getResidentialSurchargeCost()));
                        }
                        //AHS
                        if ("AM".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                            //操作附加费-超尺寸成本
                            if (item.getAHSDimensions().compareTo(BigDecimal.ZERO) > 0) {
                                if (partition == 2) {
                                    item.setAHSDimensionsCost(new BigDecimal(3.50).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 3 || partition == 4) {
                                    item.setAHSDimensionsCost(new BigDecimal(3.90).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 5 || partition == 6) {
                                    item.setAHSDimensionsCost(new BigDecimal(4.40).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition >= 7) {
                                    item.setAHSDimensionsCost(new BigDecimal(4.90).setScale(2, RoundingMode.HALF_UP));
                                }
                                item.setAmount(item.getAmount().add(item.getAHSDimensionsCost()));

                            }
                            //操作附加费-超重成本
                            if (item.getAHSWeight().compareTo(BigDecimal.ZERO) > 0) {
                                if (partition == 2) {
                                    item.setAHSWeightCost(new BigDecimal(5.70).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 3 || partition == 4) {
                                    item.setAHSWeightCost(new BigDecimal(5.90).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 5 || partition == 6) {
                                    item.setAHSWeightCost(new BigDecimal(6.30).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition >= 7) {
                                    item.setAHSWeightCost(new BigDecimal(6.90).setScale(2, RoundingMode.HALF_UP));
                                }
                                item.setAmount(item.getAmount().add(item.getAHSWeightCost()));
                            }
                            //超大超尺寸(区分-(Home Delivery)/(Ground))
                            if (item.getOversizeCharge().compareTo(BigDecimal.ZERO) > 0) {
                                if (item.getLogisticsMethod().contains("DELIVERY")) {
                                    if (partition == 2) {
                                        item.setOversizeChargeCost(new BigDecimal(38.93).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 3 || partition == 4) {
                                        item.setOversizeChargeCost(new BigDecimal(42.18).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 5 || partition == 6) {
                                        item.setOversizeChargeCost(new BigDecimal(47.05).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition >= 7) {
                                        item.setOversizeChargeCost(new BigDecimal(49.48).setScale(2, RoundingMode.HALF_UP));
                                    }
                                } else if (item.getLogisticsMethod().contains("GROUND")) {
                                    if (partition == 2) {
                                        item.setOversizeChargeCost(new BigDecimal(33.25).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 3 || partition == 4) {
                                        item.setOversizeChargeCost(new BigDecimal(36.50).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 5 || partition == 6) {
                                        item.setOversizeChargeCost(new BigDecimal(38.93).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition >= 7) {
                                        item.setOversizeChargeCost(new BigDecimal(42.18).setScale(2, RoundingMode.HALF_UP));
                                    }
                                }
                                item.setAmount(item.getAmount().add(item.getOversizeChargeCost()));
                            }

                        }
                        if ("EO".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                            //克转千克再*202046
                            BigDecimal actualWeight = item.getWeight().multiply(conversionFactor).setScale(2, RoundingMode.HALF_UP);
                            //长宽高转为英尺
                            BigDecimal acreLength = item.getLength().multiply(acre).setScale(0, RoundingMode.UP);
                            BigDecimal acreWidth = item.getWidth().multiply(acre).setScale(0, RoundingMode.UP);
                            BigDecimal acreHeight = item.getHeight().multiply(acre).setScale(0, RoundingMode.UP);
                            //围长
                            // perimeter=max(length,width,height)+(length+width+height−max(length,width,height))×2
                            // 计算最长边
                            BigDecimal maxSide = acreLength.max(acreWidth).max(acreHeight);
                            // 计算最短边
                            BigDecimal minSide = acreLength.min(acreWidth).min(acreHeight);
                            //总长度
                            BigDecimal all = acreLength.add(acreWidth).add(acreHeight);
                            // 计算第二长的边
                            BigDecimal secondMaxSide = all.subtract(maxSide).subtract(minSide);
                            // 计算另外两个值的和
                            BigDecimal sumOfOtherTwo = all.subtract(maxSide);
                            // 最终结果：最大值 + 2 * (另外两个值相加)
                            BigDecimal perimeter = maxSide.add(sumOfOtherTwo.multiply(new BigDecimal(2)));
                            if (perimeter.compareTo(new BigDecimal(125)) > 0 && perimeter.compareTo(new BigDecimal(130)) < 0) {
                                //超重
                                if (actualWeight.compareTo(new BigDecimal(50)) >= 0 && actualWeight.compareTo(new BigDecimal(150)) <= 0) {
                                    if (partition == 2) {
                                        item.setAHSWeightCost(new BigDecimal(5.70).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 3 || partition == 4) {
                                        item.setAHSWeightCost(new BigDecimal(5.90).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 5 || partition == 6) {
                                        item.setAHSWeightCost(new BigDecimal(6.30).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition >= 7) {
                                        item.setAHSWeightCost(new BigDecimal(6.90).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    item.setAmount(item.getAmount().add(item.getAHSWeightCost()));
                                } else if ((perimeter.compareTo(new BigDecimal("105")) > 0 && perimeter.compareTo(new BigDecimal("129")) <= 0) ||
                                        (secondMaxSide.compareTo(new BigDecimal("30")) >= 0) ||
                                        (maxSide.compareTo(new BigDecimal("48")) >= 0 && maxSide.compareTo(new BigDecimal("96")) <= 0)) {
                                    if (partition == 2) {
                                        item.setAHSDimensionsCost(new BigDecimal(3.50).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 3 || partition == 4) {
                                        item.setAHSDimensionsCost(new BigDecimal(3.90).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 5 || partition == 6) {
                                        item.setAHSDimensionsCost(new BigDecimal(4.40).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition >= 7) {
                                        item.setAHSDimensionsCost(new BigDecimal(4.90).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    item.setAmount(item.getAmount().add(item.getAHSDimensionsCost()));
                                }
                            } else {

                                if ("EO".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                                    if (partition == 2) {
                                        item.setOversizeChargeCost(new BigDecimal(24.00).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 3 || partition == 4) {
                                        item.setOversizeChargeCost(new BigDecimal(26.00).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 5 || partition == 6) {
                                        item.setOversizeChargeCost(new BigDecimal(35.00).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition >= 7) {
                                        item.setOversizeChargeCost(new BigDecimal(37.00).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    item.setAmount(item.getAmount().add(item.getOversizeChargeCost()));
                                } else if (item.getLogisticsMethod().contains("GROUND_OS")) {
                                    if (partition == 2) {
                                        item.setOversizeChargeCost(new BigDecimal(16.00).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 3 || partition == 4) {
                                        item.setOversizeChargeCost(new BigDecimal(18.00).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 5 || partition == 6) {
                                        item.setOversizeChargeCost(new BigDecimal(24.00).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition >= 7) {
                                        item.setOversizeChargeCost(new BigDecimal(26.00).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    item.setAmount(item.getAmount().add(item.getOversizeChargeCost()));
                                }

                            }
                        }
                        //燃油附加费利率
                        BigDecimal interestRate = item.getFuelSurcharge().divide(
                                item.getTotalCost().subtract(item.getFuelSurcharge()),
                                2,
                                RoundingMode.HALF_UP
                        );
                        if (interestRate.compareTo(BigDecimal.ZERO) != 0) {
                            item.setFuelSurchargeCost(item.getAmount().multiply(interestRate).setScale(2, RoundingMode.HALF_UP));
                            item.setAmount(item.getAmount().add(item.getFuelSurchargeCost()));
                        }
                    }

                }
            }
        });

        // 创建输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 使用 EasyExcel 创建 Excel 写入器
        try {
            // 初始化写入器
            var excelWriter = EasyExcel.write(outputStream).head(CustomerCost.class).build();
            // 创建一个 WriteSheet 对象，用于指定工作表的名称
            WriteSheet writeSheet = EasyExcel.writerSheet("汇总").head(getCustomerCost()).build();
            // 将所有数据写入这个工作表
            excelWriter.write(costList, writeSheet);
            // 关闭写入器
            excelWriter.finish();
            // 设置响应头，指示浏览器下载
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Content-Disposition", "attachment; filename=fileName.xlsx");
            // 写入输出流
            response.getOutputStream().write(outputStream.toByteArray());
            response.getOutputStream().flush();
        } finally {
            outputStream.close();
        }
        System.out.println("666677777777777777777777777777777777777777777777766");

    }

    /**
     * 标准版本
     */
    @Override
    public void customerCostStandard(HttpServletResponse response, MultipartFile costFile, MultipartFile detailsFile, boolean updateSupport) throws Exception {
        System.out.println("----------------------------------客户的成本标准版本-----------------------------");
        //导入库内操作表
        ExcelUtil<CustomerCost> costUtil = new ExcelUtil<CustomerCost>(CustomerCost.class);
        List<CustomerCost> costList = new ArrayList<>();
        String type = null;
        // 导入第一个Excel文件
        if (costFile.getOriginalFilename() != null) {
            costList = costUtil.importExcel(costFile.getInputStream());
            if (costFile.getOriginalFilename().contains("一件代发")) {
                type = "AM";
            }
        }
        //AE基础费用
        List<CustomerBasicRate> AMCustomer = customerBillMapper.getCustomerStandardAM();
        //AM
        List<CustomerBasicRate> AECustomer = customerBillMapper.getCustomerStandardAE();
        //ECONOMY 偏远 超偏远邮编
        List<EconomyDTO> economyCodeList = customerBillMapper.getEconomyCode();
        //实重(LB)
        BigDecimal conversionFactor = new BigDecimal("0.0022046");
        //英尺换算--0.393700787402
        BigDecimal acre = new BigDecimal("0.393700787402");
        costList.remove(0);
        for (CustomerCost lo : costList) {
            // 构造错误信息
            List<List<String>> data = new ArrayList<>();
            if (lo.getPostalCode().length() < 5) {
                data.add(Collections.singletonList("邮编长度错误,邮编为:" + lo.getPostalCode()));
            } else if (lo.getLength() == null || lo.getHeight() == null || lo.getWidth() == null || lo.getWeight() == null) {
                data.add(Collections.singletonList("长宽高计费重错误,运单号为为::" + lo.getWaybillNum()));
            } else if (lo.getLogisticsProvider() == null || lo.getLogisticsMethod() == null) {
                data.add(Collections.singletonList("物流商或物流方式错误,运单号为为::" + lo.getWaybillNum()));
            } else if (lo.getPartition() == null || lo.getPartition().isEmpty()) {
                data.add(Collections.singletonList("分区错误,运单号为为::" + lo.getWaybillNum()));
            }
            // 如果有错误信息，则立即导出并返回
            if (!data.isEmpty()) {
                // 设置响应头
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                response.setHeader("Content-Disposition", "attachment; filename=error_info.xlsx");

                try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
                    // 设置表头
                    List<List<String>> head = new ArrayList<>();
                    head.add(Collections.singletonList("错误"));

                    // 使用 EasyExcel 写入错误数据
                    EasyExcel.write(outputStream)
                            .head(head)
                            .sheet("错误信息")
                            .doWrite(data);

                    response.getOutputStream().write(outputStream.toByteArray());
                    response.getOutputStream().flush();
                }
                return; // 提前结束方法，只导出当前错误信息，其他不处理
            }
        }
        costList.parallelStream().forEach(item -> {
            if ("FedEx".equalsIgnoreCase(item.getLogisticsProvider()) && !("wareHouse").equals(item.getWareHouse())) {
                customerCost(item);
                if (!"是".equals(item.getWaybill()) && !"-".equals(item.getLogisticsMethod()) && item.getLogisticsMethod() != null) {
                    Integer partition = Integer.valueOf(item.getPartition());
                    //AE
                    if ("AE".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                        //基础运费成本
                        for (CustomerBasicRate rate : AECustomer) {
                            if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                                    && rate.getZones().equals(item.getPartition())
                            ) {
                                item.setBaseRateCost(rate.getPrice());
                                item.setAmount(item.getAmount().add(rate.getPrice()));
                                break;
                            }
                        }
                        //住宅附加费
                        if (item.getResidentialSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                            item.setResidentialSurchargeCost(new BigDecimal(2.40).setScale(2, RoundingMode.HALF_UP));
                            item.setDemandResidentialDeliveryChargeCost(new BigDecimal(1.10));
                            item.setAmount(item.getAmount().add(item.getResidentialSurchargeCost()).add(item.getDemandResidentialDeliveryChargeCost()));
                        }
                        //偏远地区
                        for (EconomyDTO dto : economyCodeList) {
                            if (dto.getCode().equals(item.getPostalCode().trim().substring(0, 5))) {
                                if ("偏远".equals(dto.getType())) {
                                    if (item.getDeliveryAreaSurcharge() != null) {
                                        if (item.getDeliveryAreaSurcharge().compareTo(new BigDecimal(2.51)) >= 0) {
                                            item.setDeliveryAreaSurchargeCost(new BigDecimal(3.70));
                                        } else {
                                            item.setDeliveryAreaSurchargeCost(new BigDecimal(2.51));
                                        }
                                    } else {
                                        item.setDeliveryAreaSurchargeCost(new BigDecimal(3.70).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    item.setAmount(item.getAmount().add(item.getDeliveryAreaSurchargeCost()));
                                    break;
                                } else if ("超偏远".equals(dto.getType())) {
                                    if (item.getDASEXTENDEDHomeDelivery() != null) {
                                        if (item.getDeliveryAreaSurcharge().compareTo(new BigDecimal(3.14)) >= 0) {
                                            item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal(4.95));
                                        } else {
                                            item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal(3.14));
                                        }
                                    } else {
                                        item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal(4.95));
                                    }
                                    item.setAmount(item.getAmount().add(item.getDeliveryAreaSurchargeExtendedCost()));
                                    break;
                                } else if ("超级偏远".equals(dto.getType())) {
                                    item.setDeliveryAreaSurchargeRemoteResidentialCost(new BigDecimal(8.86).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDeliveryAreaSurchargeRemoteResidentialCost()));
                                    break;
                                }
                            }
                        }
                        //包裹旺季附加费
                        item.setDemandSurchargeCost(new BigDecimal(0.40).setScale(2, RoundingMode.HALF_UP));
                        item.setAmount(item.getAmount().add(item.getDemandSurchargeCost()));
                        //燃油附加费利率
                        BigDecimal interestRate = item.getFuelSurcharge().divide(
                                item.getTotalCost().subtract(item.getFuelSurcharge()),
                                2,
                                RoundingMode.HALF_UP
                        );
                        if (interestRate.compareTo(BigDecimal.ZERO) != 0) {
                            item.setFuelSurchargeCost(item.getAmount().multiply(interestRate).setScale(2, RoundingMode.HALF_UP));
                            item.setAmount(item.getAmount().add(item.getFuelSurchargeCost()));
                        }

                    }
                    //AM-AEO
                    if ("AM".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                            "EO".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                            "_A".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                        //基础运费成本
                        for (CustomerBasicRate rate : AMCustomer) {
                            if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                                    && rate.getZones().equals(item.getPartition())
                            ) {
                                item.setBaseRateCost(rate.getPrice());
                                item.setAmount(item.getAmount().add(rate.getPrice()));
                                break;
                            }
                        }
                        //--------------------------------
                        //偏远地区附加费1
                        if (item.getDASResi() != null) {
                            if (item.getDASResi().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASResiCost(new BigDecimal("3.70"));
                                item.setAmount(item.getDASResiCost().add(item.getAmount()));
                            }
                        }
                        //偏远地区附加费2
                        if (item.getDASGround() != null) {
                            if (item.getDASGround().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASGroundCost(new BigDecimal("2.51"));
                                item.setAmount(item.getDASGroundCost().add(item.getAmount()));
                            }
                        }
                        //偏远地区附加费3
                        if (item.getDeliveryAreaSurcharge() != null) {
                            if (item.getDeliveryAreaSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDeliveryAreaSurchargeCost(new BigDecimal("3.70"));
                                item.setAmount(item.getDeliveryAreaSurchargeCost().add(item.getAmount()));
                            }
                        }
                        //超偏远地区附加费1
                        if (item.getDASEXTENDEDHomeDelivery() != null) {
                            if (item.getDASEXTENDEDHomeDelivery().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASEXTENDEDHomeDeliveryCost(new BigDecimal("4.95"));
                                item.setAmount(item.getDASEXTENDEDHomeDeliveryCost().add(item.getAmount()));
                            }
                        }
                        //超偏远地区附加费2
                        if (item.getDASEXTENDEDGround() != null) {
                            if (item.getDASEXTENDEDGround().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASEXTENDEDGroundCost(new BigDecimal("3.14"));
                                item.setAmount(item.getDASEXTENDEDGroundCost().add(item.getAmount()));
                            }
                        }
                        //超偏远地区附加费3
                        if (item.getDeliveryAreaSurchargeExtended() != null) {
                            if (item.getDeliveryAreaSurchargeExtended().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal("4.95"));
                                item.setAmount(item.getDeliveryAreaSurchargeExtendedCost().add(item.getAmount()));
                            }
                        }
                        //超级偏远地区附加费1
                        if (item.getDASRemoteComm() != null) {
                            if (item.getDASRemoteComm().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASRemoteCommCost(new BigDecimal("8.86"));
                                item.setAmount(item.getDASRemoteCommCost().add(item.getAmount()));
                            }
                        }
                        //超级偏远地区附加费2
                        if (item.getDASRemoteResi() != null) {
                            if (item.getDASRemoteResi().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASRemoteResiCost(new BigDecimal("8.86"));
                                item.setAmount(item.getDASRemoteResiCost().add(item.getAmount()));
                            }
                        }
                        //超级偏远地区附加费3
                        if (item.getDeliveryAreaSurchargeRemoteResidential() != null) {
                            if (item.getDeliveryAreaSurchargeRemoteResidential().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDeliveryAreaSurchargeRemoteResidentialCost(new BigDecimal("8.86"));
                                item.setAmount(item.getDeliveryAreaSurchargeRemoteResidentialCost().add(item.getAmount()));
                            }
                        }
                        //住宅附加
                        if (item.getResidentialSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                            item.setResidentialSurchargeCost(new BigDecimal(2.90));
                        }
                        //住宅旺季
                        if (item.getDemandResidentialDeliveryCharge().compareTo(BigDecimal.ZERO) > 0) {
                            item.setDemandResidentialDeliveryChargeCost(new BigDecimal(1.10));
                            item.setAmount(item.getAmount().add(item.getResidentialSurchargeCost()).add(item.getDemandResidentialDeliveryChargeCost()));
                        }
                        //AHS
                        if ("AM".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                                "_A".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                            //操作附加费-超尺寸成本
                            //（AM报价）AHS旺季附加费-Demand - AHS Charge
                            if (item.getAHSDimensions().compareTo(BigDecimal.ZERO) > 0) {
                                if (partition == 2) {
                                    item.setDemandAHSChargeCost(new BigDecimal(1.65).setScale(2, RoundingMode.HALF_UP));
                                    item.setAHSDimensionsCost(new BigDecimal(2.80).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 3 || partition == 4) {
                                    item.setDemandAHSChargeCost(new BigDecimal(3.29).setScale(2, RoundingMode.HALF_UP));
                                    item.setAHSDimensionsCost(new BigDecimal(3.10).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 5 || partition == 6) {
                                    item.setDemandAHSChargeCost(new BigDecimal(3.29).setScale(2, RoundingMode.HALF_UP));
                                    item.setAHSDimensionsCost(new BigDecimal(3.60).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition >= 7) {
                                    item.setDemandAHSChargeCost(new BigDecimal(3.29).setScale(2, RoundingMode.HALF_UP));
                                    item.setAHSDimensionsCost(new BigDecimal(3.80).setScale(2, RoundingMode.HALF_UP));
                                }
                                item.setAmount(item.getAmount().add(item.getAHSDimensionsCost()).add(item.getDemandAHSChargeCost()));

                            }
                            //操作附加费-超重成本

                            if (item.getAHSWeight().compareTo(BigDecimal.ZERO) > 0) {
                                if (partition == 2) {
                                    item.setAHSWeightCost(new BigDecimal(4.35).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 3 || partition == 4) {
                                    item.setAHSWeightCost(new BigDecimal(4.75).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 5 || partition == 6) {
                                    item.setAHSWeightCost(new BigDecimal(5.28).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition >= 7) {
                                    item.setAHSWeightCost(new BigDecimal(5.50).setScale(2, RoundingMode.HALF_UP));
                                }
                                item.setAmount(item.getAmount().add(item.getAHSWeightCost()));
                                //超重都是1.65 //（AM报价）AHS旺季附加费-超重
                                if(item.getDemandAHSCharge().compareTo(BigDecimal.ZERO)>0){
                                    item.setDemandAHSChargeCost(new BigDecimal(1.65).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDemandAHSChargeCost()));
                                }
                            }
                            //超大超尺寸(区分-(Home Delivery)/(Ground))
                            if (item.getOversizeCharge().compareTo(BigDecimal.ZERO) > 0) {
                                if (partition == 2) {
                                    item.setOversizeChargeCost(new BigDecimal(27.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 3 || partition == 4) {
                                    item.setOversizeChargeCost(new BigDecimal(29.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 5 || partition == 6) {
                                    item.setOversizeChargeCost(new BigDecimal(32.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition >= 7) {
                                    item.setOversizeChargeCost(new BigDecimal(34.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                item.setAmount(item.getAmount().add(item.getOversizeChargeCost()));
                            }
                            //旺季超大超尺寸附加费
                            if (item.getDemandOversizeSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDemandOversizeSurchargeCost(new BigDecimal(18).setScale(2, RoundingMode.HALF_UP));
                                item.setAmount(item.getAmount().add(item.getDemandOversizeSurchargeCost()));
                            }

                        }
                        if ("EO".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                            //克转千克再*202046
                            BigDecimal actualWeight = item.getWeight().multiply(conversionFactor).setScale(2, RoundingMode.HALF_UP);
                            //长宽高转为英尺
                            BigDecimal acreLength = item.getLength().multiply(acre).setScale(0, RoundingMode.UP);
                            BigDecimal acreWidth = item.getWidth().multiply(acre).setScale(0, RoundingMode.UP);
                            BigDecimal acreHeight = item.getHeight().multiply(acre).setScale(0, RoundingMode.UP);
                            //围长
                            // perimeter=max(length,width,height)+(length+width+height−max(length,width,height))×2
                            // 计算最长边
                            BigDecimal maxSide = acreLength.max(acreWidth).max(acreHeight);
                            // 计算最短边
                            BigDecimal minSide = acreLength.min(acreWidth).min(acreHeight);
                            //总长度
                            BigDecimal all = acreLength.add(acreWidth).add(acreHeight);
                            // 计算第二长的边
                            BigDecimal secondMaxSide = all.subtract(maxSide).subtract(minSide);
                            // 计算另外两个值的和
                            BigDecimal sumOfOtherTwo = all.subtract(maxSide);
                            // 最终结果：最大值 + 2 * (另外两个值相加)
                            BigDecimal perimeter = maxSide.add(sumOfOtherTwo.multiply(new BigDecimal(2)));
                            if (perimeter.compareTo(new BigDecimal(125)) > 0 && perimeter.compareTo(new BigDecimal(130)) < 0) {
                                //超重
                                if (actualWeight.compareTo(new BigDecimal(50)) >= 0 && actualWeight.compareTo(new BigDecimal(150)) <= 0) {
                                    if (partition == 2) {
                                        item.setAHSWeightCost(new BigDecimal(4.35).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 3 || partition == 4) {
                                        item.setAHSWeightCost(new BigDecimal(4.75).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 5 || partition == 6) {
                                        item.setAHSWeightCost(new BigDecimal(5.28).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition >= 7) {
                                        item.setAHSWeightCost(new BigDecimal(5.50).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    item.setAmount(item.getAmount().add(item.getAHSWeightCost()));
                                } else if ((perimeter.compareTo(new BigDecimal("105")) > 0 && perimeter.compareTo(new BigDecimal("129")) <= 0) ||
                                        (secondMaxSide.compareTo(new BigDecimal("30")) >= 0) ||
                                        (maxSide.compareTo(new BigDecimal("48")) >= 0 && maxSide.compareTo(new BigDecimal("96")) <= 0)) {
                                    if (partition == 2) {
                                        item.setAHSDimensionsCost(new BigDecimal(2.80).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 3 || partition == 4) {
                                        item.setAHSDimensionsCost(new BigDecimal(3.10).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 5 || partition == 6) {
                                        item.setAHSDimensionsCost(new BigDecimal(3.60).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition >= 7) {
                                        item.setAHSDimensionsCost(new BigDecimal(3.80).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    item.setAmount(item.getAmount().add(item.getAHSDimensionsCost()));
                                }
                            } else {
                                if ("EO".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                                    if (partition == 2) {
                                        item.setOversizeChargeCost(new BigDecimal(27.00).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 3 || partition == 4) {
                                        item.setOversizeChargeCost(new BigDecimal(29.00).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 5 || partition == 6) {
                                        item.setOversizeChargeCost(new BigDecimal(32.00).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition >= 7) {
                                        item.setOversizeChargeCost(new BigDecimal(34.00).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    item.setAmount(item.getAmount().add(item.getOversizeChargeCost()));
                                }
                                //超大尺寸附加费旺季附加费（9.29-11.23）
                                if(item.getDemandOversizeSurcharge().compareTo(BigDecimal.ZERO)>0){
                                    item.setDemandOversizeSurchargeCost(new BigDecimal(18.00).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDemandOversizeSurchargeCost()));
                                }
                            }
                        }
                        //包裹旺季附加费
                        if(item.getDemandSurcharge().compareTo(BigDecimal.ZERO)>0){
                            item.setDemandSurchargeCost(new BigDecimal(0.40).setScale(2, RoundingMode.HALF_UP));
                            item.setAmount(item.getAmount().add(item.getDemandSurchargeCost()));
                        }
                        //燃油附加费利率
                        BigDecimal interestRate = item.getFuelSurcharge().divide(
                                item.getTotalCost().subtract(item.getFuelSurcharge()),
                                2,
                                RoundingMode.HALF_UP
                        );
                        if (interestRate.compareTo(BigDecimal.ZERO) != 0) {
                            item.setFuelSurchargeCost(item.getAmount().multiply(interestRate).setScale(2, RoundingMode.HALF_UP));
                            item.setAmount(item.getAmount().add(item.getFuelSurchargeCost()));
                        }
                    }
                }
            }
        });

        // 创建输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 使用 EasyExcel 创建 Excel 写入器
        try {
            // 初始化写入器
            var excelWriter = EasyExcel.write(outputStream).head(CustomerCost.class).build();
            // 创建一个 WriteSheet 对象，用于指定工作表的名称
            WriteSheet writeSheet = EasyExcel.writerSheet("汇总").head(getCustomerCost()).build();
            // 将所有数据写入这个工作表
            excelWriter.write(costList, writeSheet);
            // 关闭写入器
            excelWriter.finish();
            // 设置响应头，指示浏览器下载
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Content-Disposition", "attachment; filename=fileName.xlsx");
            // 写入输出流
            response.getOutputStream().write(outputStream.toByteArray());
            response.getOutputStream().flush();
        } finally {
            outputStream.close();
        }
        System.out.println("666677777777777777777777777777777777777777777777766");

    }

    /**
     * vvip版本
     */
    @Override
    public void customerCostVip(HttpServletResponse response, MultipartFile costFile, MultipartFile detailsFile, boolean updateSupport) throws Exception {
        System.out.println("----------------------------------客户的成本vvip-----------------------------");
        //导入库内操作表
        ExcelUtil<CustomerCost> costUtil = new ExcelUtil<CustomerCost>(CustomerCost.class);
        List<CustomerCost> costList = new ArrayList<>();
        String type = null;
        // 导入第一个Excel文件
        if (costFile.getOriginalFilename() != null) {
            costList = costUtil.importExcel(costFile.getInputStream());
            if (costFile.getOriginalFilename().contains("一件代发")) {
                type = "AM";
            }
        }
        //AM客户基础费用
        List<CustomerBasicRate> AMCustomer = customerBillMapper.getCustomerVVIPAM();
        //ECO客户基础费用
        List<CustomerBasicRate> ECOCustomer = customerBillMapper.getCustomerVVIPECO();
        //ECONOMY 偏远 超偏远邮编
        List<EconomyDTO> economyCodeList = customerBillMapper.getEconomyCode();
        //实重(LB)
        BigDecimal conversionFactor = new BigDecimal("0.0022046");
        //英尺换算--0.393700787402
        BigDecimal acre = new BigDecimal("0.393700787402");
        costList.remove(0);
        for (CustomerCost lo : costList) {
            // 构造错误信息
            List<List<String>> data = new ArrayList<>();
            if (lo.getPostalCode().length() < 5) {
                data.add(Collections.singletonList("邮编长度错误,邮编为:" + lo.getPostalCode()));
            } else if (lo.getLength() == null || lo.getHeight() == null || lo.getWidth() == null || lo.getWeight() == null) {
                data.add(Collections.singletonList("长宽高计费重错误,运单号为为::" + lo.getWaybillNum()));
            } else if (lo.getLogisticsProvider() == null || lo.getLogisticsMethod() == null) {
                data.add(Collections.singletonList("物流商或物流方式错误,运单号为为::" + lo.getWaybillNum()));
            } else if (lo.getPartition() == null || lo.getPartition().isEmpty()) {
                data.add(Collections.singletonList("分区错误,运单号为为::" + lo.getWaybillNum()));
            }
            // 如果有错误信息，则立即导出并返回
            if (!data.isEmpty()) {
                // 设置响应头
                response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                response.setHeader("Content-Disposition", "attachment; filename=error_info.xlsx");

                try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
                    // 设置表头
                    List<List<String>> head = new ArrayList<>();
                    head.add(Collections.singletonList("错误"));

                    // 使用 EasyExcel 写入错误数据
                    EasyExcel.write(outputStream)
                            .head(head)
                            .sheet("错误信息")
                            .doWrite(data);

                    response.getOutputStream().write(outputStream.toByteArray());
                    response.getOutputStream().flush();
                }
                return; // 提前结束方法，只导出当前错误信息，其他不处理
            }
        }
        costList.parallelStream().forEach(item -> {
            if ("FedEx".equalsIgnoreCase(item.getLogisticsProvider()) && !("wareHouse").equals(item.getWareHouse())) {
                customerCost(item);
                if (!"是".equals(item.getWaybill()) && !"-".equals(item.getLogisticsMethod()) && item.getLogisticsMethod() != null) {
                    Integer partition = Integer.valueOf(item.getPartition());
                    //ECO
                    if (item.getLogisticsMethod().contains("ECONOMY")) {
                        //基础运费成本
                        for (CustomerBasicRate rate : ECOCustomer) {
                            if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                                    && rate.getZones().equals(item.getPartition())) {
                                item.setBaseRateCost(rate.getPrice());
                                item.setAmount(item.getAmount().add(item.getBaseRateCost()));
                                break;
                            }
                        }
                        //偏远地区
                        for (EconomyDTO dto : economyCodeList) {
                            if (dto.getCode().equals(item.getPostalCode().trim().substring(0, 5))) {
                                if ("偏远".equals(dto.getType())) {
                                    item.setDeliveryAreaSurchargeCost(new BigDecimal(2.98).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDeliveryAreaSurchargeCost()));
                                    break;
                                } else if ("超偏远".equals(dto.getType())) {
                                    item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal(3.98).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDeliveryAreaSurchargeExtendedCost()));
                                    break;
                                } else if ("超级偏远".equals(dto.getType())) {
                                    item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal(3.98).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDeliveryAreaSurchargeExtendedCost()));
                                    break;
                                }
                            }
                        }
                        //包裹旺季附加费
                        item.setDemandSurchargeCost(new BigDecimal(0.40).setScale(2, RoundingMode.HALF_UP));
                        item.setAmount(item.getAmount().add(item.getDemandSurchargeCost()));
                        //燃油附加费利率
                        BigDecimal interestRate = item.getFuelSurcharge().divide(
                                item.getTotalCost().subtract(item.getFuelSurcharge()), 2, RoundingMode.HALF_UP);
                        if (interestRate.compareTo(BigDecimal.ZERO) != 0) {
                            item.setFuelSurchargeCost(item.getAmount().multiply(interestRate).setScale(2, RoundingMode.HALF_UP));
                            item.setAmount(item.getAmount().add(item.getFuelSurchargeCost()));
                        }


                    }
                    if ("AM".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                            "EO".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                            "_B".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                        //基础运费成本
                        for (CustomerBasicRate rate : AMCustomer) {
                            if (rate.getWeight().equals(item.getBillingWeight().setScale(0, RoundingMode.CEILING))
                                    && rate.getZones().equals(item.getPartition())
                            ) {
                                item.setBaseRateCost(rate.getPrice());
                                item.setAmount(item.getAmount().add(rate.getPrice()));
                                break;
                            }
                        }
                        //--------------------------------
                        //偏远地区附加费1
                        if (item.getDASResi() != null) {
                            if (item.getDASResi().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASResiCost(new BigDecimal("3.70"));
                                item.setAmount(item.getDASResiCost().add(item.getAmount()));
                            }
                        }
                        //偏远地区附加费2
                        if (item.getDASGround() != null) {
                            if (item.getDASGround().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASGroundCost(new BigDecimal("2.51"));
                                item.setAmount(item.getDASGroundCost().add(item.getAmount()));
                            }
                        }
                        //偏远地区附加费3
                        if (item.getDeliveryAreaSurcharge() != null) {
                            if (item.getDeliveryAreaSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDeliveryAreaSurchargeCost(new BigDecimal("3.70"));
                                item.setAmount(item.getDeliveryAreaSurchargeCost().add(item.getAmount()));
                            }
                        }
                        //超偏远地区附加费1
                        if (item.getDASEXTENDEDHomeDelivery() != null) {
                            if (item.getDASEXTENDEDHomeDelivery().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASEXTENDEDHomeDeliveryCost(new BigDecimal("4.95"));
                                item.setAmount(item.getDASEXTENDEDHomeDeliveryCost().add(item.getAmount()));
                            }
                        }
                        //超偏远地区附加费2
                        if (item.getDASEXTENDEDGround() != null) {
                            if (item.getDASEXTENDEDGround().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASEXTENDEDGroundCost(new BigDecimal("3.14"));
                                item.setAmount(item.getDASEXTENDEDGroundCost().add(item.getAmount()));
                            }
                        }
                        //超偏远地区附加费3
                        if (item.getDeliveryAreaSurchargeExtended() != null) {
                            if (item.getDeliveryAreaSurchargeExtended().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal("4.95"));
                                item.setAmount(item.getDeliveryAreaSurchargeExtendedCost().add(item.getAmount()));
                            }
                        }
                        //超级偏远地区附加费1
                        if (item.getDASRemoteComm() != null) {
                            if (item.getDASRemoteComm().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASRemoteCommCost(new BigDecimal("8.86"));
                                item.setAmount(item.getDASRemoteCommCost().add(item.getAmount()));
                            }
                        }
                        //超级偏远地区附加费2
                        if (item.getDASRemoteResi() != null) {
                            if (item.getDASRemoteResi().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDASRemoteResiCost(new BigDecimal("8.86"));
                                item.setAmount(item.getDASRemoteResiCost().add(item.getAmount()));
                            }
                        }
                        //超级偏远地区附加费3
                        if (item.getDeliveryAreaSurchargeRemoteResidential() != null) {
                            if (item.getDeliveryAreaSurchargeRemoteResidential().compareTo(BigDecimal.ZERO) > 0) {
                                item.setDeliveryAreaSurchargeRemoteResidentialCost(new BigDecimal("8.86"));
                                item.setAmount(item.getDeliveryAreaSurchargeRemoteResidentialCost().add(item.getAmount()));
                            }
                        }
                        //住宅附加
                        if (item.getResidentialSurcharge().compareTo(BigDecimal.ZERO) > 0) {
                            item.setResidentialSurchargeCost(new BigDecimal(2.90));

                            item.setAmount(item.getAmount().add(item.getResidentialSurchargeCost()));
                        }
                        //旺季住宅附加
                        if(item.getDemandResidentialDeliveryCharge().compareTo(BigDecimal.ZERO)>0){
                            item.setDemandResidentialDeliveryChargeCost(new BigDecimal(1.10));
                            item.setAmount(item.getAmount().add(item.getDemandResidentialDeliveryChargeCost()));
                        }
                        //AHS
                        if ("AM".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2)) ||
                                "_B".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                            //操作附加费-超尺寸成本
                            //（AM报价）AHS旺季附加费-Demand - AHS Charge
                            if (item.getAHSDimensions().compareTo(BigDecimal.ZERO) > 0) {
                                if (partition == 2) {
                                    item.setDemandAHSChargeCost(new BigDecimal(1.65).setScale(2, RoundingMode.HALF_UP));
                                    item.setAHSDimensionsCost(new BigDecimal(2.80).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 3 || partition == 4) {
                                    item.setDemandAHSChargeCost(new BigDecimal(3.29).setScale(2, RoundingMode.HALF_UP));
                                    item.setAHSDimensionsCost(new BigDecimal(3.10).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 5 || partition == 6) {
                                    item.setDemandAHSChargeCost(new BigDecimal(3.29).setScale(2, RoundingMode.HALF_UP));
                                    item.setAHSDimensionsCost(new BigDecimal(3.60).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition >= 7) {
                                    item.setDemandAHSChargeCost(new BigDecimal(3.29).setScale(2, RoundingMode.HALF_UP));
                                    item.setAHSDimensionsCost(new BigDecimal(3.80).setScale(2, RoundingMode.HALF_UP));
                                }
                                item.setAmount(item.getAmount().add(item.getAHSDimensionsCost()).add(item.getDemandAHSChargeCost()));

                            }
                            //操作附加费-超重成本
                            //（AM报价）AHS旺季附加费-Demand - AHS Charge
                            if (item.getAHSWeight().compareTo(BigDecimal.ZERO) > 0) {
                                if (partition == 2) {
                                    item.setAHSWeightCost(new BigDecimal(4.35).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 3 || partition == 4) {
                                    item.setAHSWeightCost(new BigDecimal(4.75).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 5 || partition == 6) {
                                    item.setAHSWeightCost(new BigDecimal(5.28).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition >= 7) {
                                    item.setAHSWeightCost(new BigDecimal(5.50).setScale(2, RoundingMode.HALF_UP));
                                }
                                item.setAmount(item.getAmount().add(item.getAHSWeightCost()));
                                //超重都是1.65 //（AM报价）AHS旺季附加费-超重
                                if(item.getDemandAHSCharge().compareTo(BigDecimal.ZERO)>0){
                                    item.setDemandAHSChargeCost(new BigDecimal(1.65).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDemandAHSChargeCost()));
                                }
                            }
                            //超大超尺寸(区分-(Home Delivery)/(Ground))
                            if (item.getOversizeCharge().compareTo(BigDecimal.ZERO) > 0) {
                                if (partition == 2) {
                                    item.setOversizeChargeCost(new BigDecimal(16.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 3 || partition == 4) {
                                    item.setOversizeChargeCost(new BigDecimal(18.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 5 || partition == 6) {
                                    item.setOversizeChargeCost(new BigDecimal(24.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition >= 7) {
                                    item.setOversizeChargeCost(new BigDecimal(26.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                item.setAmount(item.getAmount().add(item.getOversizeChargeCost()));
                                //旺季超大超尺寸
                                if(item.getDemandOversizeSurcharge().compareTo(BigDecimal.ZERO)>0){
                                    item.setDemandOversizeSurchargeCost(new BigDecimal(18).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDemandOversizeSurchargeCost()));
                                }

                            }


                        }
                        if ("EO".equals(item.getLogisticsMethod().substring(item.getLogisticsMethod().length() - 2))) {
                            //克转千克再*202046
                            BigDecimal actualWeight = item.getWeight().multiply(conversionFactor).setScale(2, RoundingMode.HALF_UP);
                            //长宽高转为英尺
                            BigDecimal acreLength = item.getLength().multiply(acre).setScale(0, RoundingMode.UP);
                            BigDecimal acreWidth = item.getWidth().multiply(acre).setScale(0, RoundingMode.UP);
                            BigDecimal acreHeight = item.getHeight().multiply(acre).setScale(0, RoundingMode.UP);
                            //围长
                            // perimeter=max(length,width,height)+(length+width+height−max(length,width,height))×2
                            // 计算最长边
                            BigDecimal maxSide = acreLength.max(acreWidth).max(acreHeight);
                            // 计算最短边
                            BigDecimal minSide = acreLength.min(acreWidth).min(acreHeight);
                            //总长度
                            BigDecimal all = acreLength.add(acreWidth).add(acreHeight);
                            // 计算第二长的边
                            BigDecimal secondMaxSide = all.subtract(maxSide).subtract(minSide);
                            // 计算另外两个值的和
                            BigDecimal sumOfOtherTwo = all.subtract(maxSide);
                            // 最终结果：最大值 + 2 * (另外两个值相加)
                            BigDecimal perimeter = maxSide.add(sumOfOtherTwo.multiply(new BigDecimal(2)));
                            if (perimeter.compareTo(new BigDecimal(125)) > 0 && perimeter.compareTo(new BigDecimal(130)) < 0) {
                                //超重
                                if (actualWeight.compareTo(new BigDecimal(50)) >= 0 && actualWeight.compareTo(new BigDecimal(150)) <= 0) {
                                    if (partition == 2) {
                                        item.setAHSWeightCost(new BigDecimal(4.35).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 3 || partition == 4) {
                                        item.setAHSWeightCost(new BigDecimal(4.75).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 5 || partition == 6) {
                                        item.setAHSWeightCost(new BigDecimal(5.28).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition >= 7) {
                                        item.setAHSWeightCost(new BigDecimal(5.50).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    item.setAmount(item.getAmount().add(item.getAHSWeightCost()));
                                } else if ((perimeter.compareTo(new BigDecimal("105")) > 0 && perimeter.compareTo(new BigDecimal("129")) <= 0) ||
                                        (secondMaxSide.compareTo(new BigDecimal("30")) >= 0) ||
                                        (maxSide.compareTo(new BigDecimal("48")) >= 0 && maxSide.compareTo(new BigDecimal("96")) <= 0)) {
                                    if (partition == 2) {
                                        item.setAHSDimensionsCost(new BigDecimal(2.80).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 3 || partition == 4) {
                                        item.setAHSDimensionsCost(new BigDecimal(3.10).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition == 5 || partition == 6) {
                                        item.setAHSDimensionsCost(new BigDecimal(3.60).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    if (partition >= 7) {
                                        item.setAHSDimensionsCost(new BigDecimal(3.80).setScale(2, RoundingMode.HALF_UP));
                                    }
                                    item.setAmount(item.getAmount().add(item.getAHSDimensionsCost()));
                                }
                            } else {
                                if (partition == 2) {
                                    item.setOversizeChargeCost(new BigDecimal(27.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 3 || partition == 4) {
                                    item.setOversizeChargeCost(new BigDecimal(29.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition == 5 || partition == 6) {
                                    item.setOversizeChargeCost(new BigDecimal(32.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                if (partition >= 7) {
                                    item.setOversizeChargeCost(new BigDecimal(34.00).setScale(2, RoundingMode.HALF_UP));
                                }
                                item.setAmount(item.getAmount().add(item.getOversizeChargeCost()));
                                //超大尺寸附加费旺季附加费（9.29-11.23）
                                if(item.getDemandOversizeSurcharge().compareTo(BigDecimal.ZERO)>0) {
                                    item.setDemandOversizeSurchargeCost(new BigDecimal(18.00).setScale(2, RoundingMode.HALF_UP));
                                    item.setAmount(item.getAmount().add(item.getDemandOversizeSurchargeCost()));
                                }
                            }
                        }
                        //包裹旺季附加费
                        if(item.getDemandSurcharge().compareTo(BigDecimal.ZERO)>0){
                            item.setDemandSurchargeCost(new BigDecimal(0.40).setScale(2, RoundingMode.HALF_UP));
                            item.setAmount(item.getAmount().add(item.getDemandSurchargeCost()));
                        }//燃油附加费利率
                        BigDecimal interestRate = item.getFuelSurcharge().divide(
                                item.getTotalCost().subtract(item.getFuelSurcharge()),
                                2,
                                RoundingMode.HALF_UP
                        );
                        if (interestRate.compareTo(BigDecimal.ZERO) != 0) {
                            item.setFuelSurchargeCost(item.getAmount().multiply(interestRate).setScale(2, RoundingMode.HALF_UP));
                            item.setAmount(item.getAmount().add(item.getFuelSurchargeCost()));
                        }

                    }

                }
            }
        });

        // 创建输出流
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        // 使用 EasyExcel 创建 Excel 写入器
        try {
            // 初始化写入器
            var excelWriter = EasyExcel.write(outputStream).head(CustomerCost.class).build();
            // 创建一个 WriteSheet 对象，用于指定工作表的名称
            WriteSheet writeSheet = EasyExcel.writerSheet("汇总").head(getCustomerCost()).build();
            // 将所有数据写入这个工作表
            excelWriter.write(costList, writeSheet);
            // 关闭写入器
            excelWriter.finish();
            // 设置响应头，指示浏览器下载
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setHeader("Content-Disposition", "attachment; filename=fileName.xlsx");
            // 写入输出流
            response.getOutputStream().write(outputStream.toByteArray());
            response.getOutputStream().flush();
        } finally {
            outputStream.close();
        }
        System.out.println("666677777777777777777777777777777777777777777777766");

    }


    private List<List<String>> getCustomerCost() {
        // 定义标题和对应的字段名称
        String[][] titlesAndFields = {
                {"出库仓库", "wareHouse"},
                {"订单编号", "orderNo"},
                {"销售平台", "salesPlatform"},
                {"提审时间", "submissionTime"},
                {"处理时间", "processingTime"},
                {"发货时间", "deliveryTime"},
                {"收货人", "consignee"},
                {"国家", "country"},
                {"州/省", "province"},
                {"城市", "city"},
                {"邮编", "postalCode"},
                {"分区", "partition"},
                {"单位", "unit"},
                {"包裹长(CM)", "length"},
                {"包裹宽(CM)", "width"},
                {"包裹高(CM)", "height"},
                {"包裹重量(g)", "weight"},
                {"计费重(LB)", "billingWeight"},
                {"SKU数量", "SKUNum"},
                {"SKU1", "SKU1"},
                {"SKU1数量", "SKU1Num"},
                {"SKU2", "SKU2"},
                {"SKU2数量", "SKU2Num"},
                {"SKU3", "SKU3"},
                {"SKU3数量", "SKU3Num"},
                {"SKU4", "SKU4"},
                {"SKU4数量", "SKU4Num"},
                {"SKU5", "SKU5"},
                {"SKU5数量", "SKU5Num"},
                {"物流商", "logisticsProvider"},
                {"物流方式", "logisticsMethod"},
                {"自有运单", "waybill"},
                {"运单号", "waybillNum"},
                {"基础运费", "Basic Rate"},
                {"操作附加费-超尺寸", "AHS - Dimensions"},
                {"操作附加费-超重", "AHS - Weight"},
                {"旺季额外附加费", "Demand - AHS Charge"},
                {"超大超尺寸", "Oversize Charge"},
                {"旺季超大超尺寸附加费", "Demand - Oversize Surcharge"},
                {"住宅附加费", "Residential Surcharge"},
                {"住宅旺季附加费", "Demand  - Residential Delivery Charge"},
                {"包裹旺季附加费", "Demand Surcharge"},
                {"偏远地区附加费1", "DAS Resi"},
                {"偏远地区附加费2", "DAS - Ground (Comm)"},
                {"偏远地区附加费3", "Delivery Area Surcharge"},
                {"超偏远地区附加费1", "DAS EXTENDED - Home Delivery (Resi)"},
                {"超偏远地区附加费2", "DAS EXTENDED - Ground (Comm)"},
                {"超偏远地区附加费3", "delivery Area Surcharge Extended"},
                {"超级偏远地区附加费1", "DAS Remote Comm(Ground)"},
                {"超级偏远地区附加费2", "DAS Remote Resi (Home Delivery)"},
                {"超级偏远地区附加费3", "Delivery Area Surcharge Remote Residential"},
                {"签名服务费", "Indirect signature required"},
                {"燃油附加费", "Fuel Surcharge"},
                {"费用合计", "totalCost"},
                {"客户编码", "customerNode"},
                {"基础运费成本", "Basic Rate Cost"},
                {"操作附加费-超尺寸成本", "AHS - Dimensions Cost"},
                {"操作附加费-超重成本", "AHS - Weight Cost"},
                {"旺季额外附加费成本", "Demand - AHS Charge Cost"},
                {"超大超尺寸成本", "Oversize Charge Cost"},
                {"旺季超大超尺寸附加费成本", "Demand - Oversize Surcharge Cost"},
                {"住宅附加费成本", "Residential Surcharge Cost"},
                {"住宅旺季附加费成本", "Demand  - Residential Delivery Charge Cost"},
                {"包裹旺季附加费成本", "Demand Surcharge Cost"},
                {"偏远地区附加费1成本", "DAS Resi Cost"},
                {"偏远地区附加费2成本", "DAS - Ground (Comm) Cost"},
                {"偏远地区附加费3成本", "Delivery Area Surcharge Cost"},
                {"超偏远地区附加费1成本", "DAS EXTENDED - Home Delivery (Resi) Cost"},
                {"超偏远地区附加费2成本", "DAS EXTENDED - Ground (Comm) Cost"},
                {"超偏远地区附加费3成本", "delivery Area Surcharge Extended Cost"},
                {"超级偏远地区附加费1成本", "DAS Remote Comm(Ground) Cost"},
                {"超级偏远地区附加费2成本", "DAS Remote Resi (Home Delivery) Cost"},
                {"超级偏远地区附加费3成本", "Delivery Area Surcharge Remote Residential Cost"},
                {"签名服务费成本", "Indirect signature required Cost"},
                {"燃油附加费成本", "Fuel Surcharge Cost"},
                {"合计", "AmountCost"},
        };

// 使用流来创建标题列表
        List<List<String>> headList = Arrays.stream(titlesAndFields)
                .map(Arrays::asList)
                .collect(Collectors.toList());
        return headList;
    }

    private void customerCost(CustomerCost item) {

        item.setBaseRateCost(new BigDecimal("0.00"));
        item.setAHSDimensionsCost(new BigDecimal("0.00"));
        item.setAHSWeightCost(new BigDecimal("0.00"));
        item.setDemandAHSChargeCost(new BigDecimal("0.00"));
        item.setOversizeChargeCost(new BigDecimal("0.00"));
        item.setDemandOversizeSurchargeCost(new BigDecimal("0.00"));
        item.setResidentialSurchargeCost(new BigDecimal("0.00"));
        item.setDemandResidentialDeliveryChargeCost(new BigDecimal("0.00"));
        item.setDemandSurchargeCost(new BigDecimal("0.00"));
        item.setDASResiCost(new BigDecimal("0.00"));
        item.setDASGroundCost(new BigDecimal("0.00"));
        item.setDeliveryAreaSurchargeCost(new BigDecimal("0.00"));
        item.setDASEXTENDEDHomeDeliveryCost(new BigDecimal("0.00"));
        item.setDASEXTENDEDGroundCost(new BigDecimal("0.00"));
        item.setDeliveryAreaSurchargeExtendedCost(new BigDecimal("0.00"));
        item.setDASRemoteCommCost(new BigDecimal("0.00"));
        item.setDASRemoteResiCost(new BigDecimal("0.00"));
        item.setDeliveryAreaSurchargeRemoteResidentialCost(new BigDecimal("0.00"));
        item.setIndirectSignatureRequiredCost(new BigDecimal("0.00"));
        item.setFuelSurchargeCost(new BigDecimal("0.00"));
        item.setAmount(new BigDecimal("0.00"));
    }
}

